
package com.jesse.base;

import com.jesse.main.R;
import com.jesse.util.ViewUtil;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.MotionEvent;

public class BaseActivity extends Activity {

	private ActivityUtil activityUtil;
	private boolean initComplete = false;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		activityUtil = new ActivityUtil();
		activityUtil.onCreate(this);
		initComplete = false;
	}
	
	@Override
	protected void onResume() {
        super.onResume();
        activityUtil.onResume(this);
        if (!initComplete) {
        	initComplete = true;
        	initActionBar();
        	initLayout();
    		initData();
    		checkGuider();
        }
    }
	 
	/**
	 * Hooks 初始化布局
	 */
	public void initLayout() {
		
	}
	
	/**
	 * Hooks 初始化ActionBar
	 */
	public void initActionBar() {
		
	}
	
	/**
	 * Hooks 初始化数据
	 */
	public void initData() {
		
	}
	
	/**
	 * Hooks 初始化新手引导
	 */
	public void checkGuider() {
		
	}
	
	//不提示网络错误提示
	public void notShowNetErrorPopup() {
		activityUtil.notShowNetErrorPopup();
	}
	
	//不提示网络错误提示
	public void notShowWiFiErrorPopup() {
		activityUtil.notShowWiFiErrorPopup();
	}
	
	//检测Wifi状态
	public boolean checkWiFiState(Context context) {
		return activityUtil.checkWiFiState(context);
	}
	
	//手勢开关
	public boolean isGestrue() {
		return activityUtil.isGestrue();
	}
	
	public void setGestrue(boolean gestrue) {
		activityUtil.setGestrue(gestrue);
	}
	
	@Override
	public boolean dispatchTouchEvent(MotionEvent event) {
		if (activityUtil.dispatchTouchEvent(this, event)) {
			finish();
			return true;
		}
		return super.dispatchTouchEvent(event);
	}
	
	public void finish() {
		if (activityUtil != null)
			activityUtil.finish(this);
		super.finish();
		finishAnimation();
	}
	
	/**
	 * 复写此方法，替换结束动画
	 */
	protected void finishAnimation() {
		overridePendingTransition(0, R.anim.out_to_left);
	}
	
	@Override
    protected void onDestroy() {
		activityUtil.onDestroy(this);
		activityUtil = null;
        super.onDestroy();
    }
}
